package com.his.diagnose.controller;

import com.his.config.annotation.CurrentUser;
import com.his.diagnose.service.DiagnosisResultService;
import com.his.diagnose.service.DictMedicalCodeIcdService;
import com.his.diagnose.vo.DiagnosisresultVo;
import com.his.diagnose.vo.GetDiagnosisVo;
import com.his.diagnose.vo.SearchDiagnosisVo;
import com.his.login.entity.DictEmployee;
import com.xiao.common.controller.ResultBaseController;
import com.xiao.common.util.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @Author xiaoxiaoping
 * @Date 2020/3/24 20:19
 * @Version 1.0
 */
@RestController
@RequestMapping(value = "/api/icd")
public class DictMedicalCodeIcdController extends ResultBaseController {
    private  final org.slf4j.Logger logger = (Logger) LoggerFactory.getLogger(this.getClass());
    @Resource
    private DictMedicalCodeIcdService dictMedicalCodeIcdService;
    @Resource
    private DiagnosisResultService diagnosisResultService;

    @RequestMapping(value="/get_icd.do")
    public ResultUtil getIcd(@CurrentUser DictEmployee dictEmployee,String ybTypeId){
        try{
            dictMedicalCodeIcdService.saveToEs();
            return this.success("",null);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }
    @PostMapping(value="/get_icd_by_condition.do")
    public ResultUtil getIcdCondition(@CurrentUser DictEmployee dictEmployee, @RequestBody SearchDiagnosisVo searchDiagnosisVo){
        try{
            return this.success("",dictMedicalCodeIcdService.queryIcdByCondition(dictEmployee,searchDiagnosisVo));
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }

    /**
     * 保存诊断
     * @param dictEmployee
     * @param diagnosisresultVo
     * @return
     */
    @PostMapping(value="/save_diagnosis.do")
    public ResultUtil saveDiagnosis(@CurrentUser DictEmployee dictEmployee,@RequestBody @Validated DiagnosisresultVo diagnosisresultVo){
        try{
            diagnosisResultService.save(dictEmployee,diagnosisresultVo);
            return this.success("保存成功！",null);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }
    @PostMapping(value="/get_diagnosis.do")
    public ResultUtil getDiagnosis(@CurrentUser DictEmployee dictEmployee, @RequestBody @Validated GetDiagnosisVo diagnosisVo){
        try{
            return this.success("",diagnosisResultService.getDiagnosis(dictEmployee,diagnosisVo));
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }
}
